/*
 * @lc app=leetcode.cn id=2766 lang=golang
 *
 * [2766] 重新放置石块
 */
package Solutions

import "slices"

// @lc code=start
func relocateMarbles(nums []int, moveFrom []int, moveTo []int) []int {
	mp := make(map[int]int, len(nums))
	for _, v := range nums {
		mp[v]++
	}
	for i, v := range moveFrom {
		if moveTo[i] == v {
			continue
		}
		mp[moveTo[i]] += mp[v]
		mp[v] = 0
	}

	ans := make([]int, 0, len(mp))
	for k, v := range mp {
		if v != 0 {
			ans = append(ans, k)
		}
	}
	slices.Sort(ans)
	return ans
}

// @lc code=end
